#include "pch.h"
#include "CTest.h"


TTest* createTest() {
	TTest* pTest = new TTest;
	pTest->_canAllocSpace = true;
	pTest->_size = 0;
	pTest->_pAllocatedSpace = nullptr;
	return pTest;
}

void releaseTest(TTest* pTest) {
	delete pTest->_pAllocatedSpace;
	pTest->_pAllocatedSpace = nullptr;
	delete pTest;
	pTest = nullptr;
}

double multi(TTest* pTest, double v1, double v2)
{
	return v1 * v2;
}

bool canAllocSpace(TTest* pTest)
{
	return pTest->_canAllocSpace;
}

void allocSpace(TTest* pTest, int size)
{
	if (pTest->_canAllocSpace == true) {
		pTest->_canAllocSpace = false;
		pTest->_pAllocatedSpace = new int[size];
		pTest->_size = size;
	}

}

int* getAllocatedSpacePtr(TTest* pTest)
{
	return pTest->_pAllocatedSpace;
}

int getAllocatedSpaceSize(TTest* pTest)
{
	return pTest->_size * sizeof(int);
}

void releaseSpace(TTest* pTest)
{
	delete pTest->_pAllocatedSpace;
	pTest->_pAllocatedSpace = nullptr;
	pTest->_canAllocSpace = true;
}

double pow(TTest* pTest, double num, int count)
{
	if (count <= 0)
		return 1;
	if (count == 1)
		return num;
	return num * pow(pTest, num, count - 1);
}

double powLoop(TTest* pTest, double num, int count, int loopCount)
{
	double rst;
	for (int i = 0; i < loopCount; i++)
	{
		rst = pow(pTest, num, count);
	}
	return rst;

}
